<?PHP
// ============= Persistence layer ============
namespace DB
{
	class Sqlite
	{
		private $db;
		private $dbInfo="mysqlitedb.db";

		public function __construct($userName, $password, $dbInfo)
		{
            $this->db = new \SQLite3($this->dbInfo);
		}

		public function query($query = '', $args=array())
		{
            //$qArgs = array();
            //$strQuery = $query;
            //foreach ($args as $key => $value)
            //{
            //	$strQuery = str_ireplace($key, "?", $strQuery);
            //	$qArgs[] = $value;
            //}
            $st = $this->db->prepare($query);

            foreach ($args as $key => $value)
            {
            	$st->bindParam($key, $value);
            }
            
            $result = $st->execute();
            $res = array();
            while ($assoc = $result->fetchArray())
            {
            	$res[] = $assoc;
            }
            
            return $res;
		}
	}
}